package com.bkhc.common.api;

import com.bkhc.common.annotation.ApiOperation;
import com.bkhc.common.annotation.ApiPackage;
import com.bkhc.common.annotation.AuditLog;
import com.bkhc.common.entity.Role;
import com.bkhc.common.enu.OperationEnum;
import com.bkhc.common.service.RoleService;
import com.bkhc.common.util.response.ResultJson;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author pcq
 * @date 2021/6/20 17:57
 */
@RestController
@RequestMapping("/role")
@Api("后台管理服务接口")
@ApiPackage(code="roleService",name="后台角色服务接口",description = "后台管理员相关角色维护操作接口")
public class RoleController extends CommonController {

    @Autowired
    private RoleService roleSerivce;
    @ApiOperation(code="queryRole",name="查询角色",description = "查询后台角色")
    @AuditLog(object="Role",operation = "查询用户",type = OperationEnum.query)
    @RequestMapping(path = "/query/{pageNum}/{pageSize}",method = RequestMethod.POST)
    public ResultJson<?> getAllRolePage(@RequestBody(required=false) Role role, @PathVariable(name="pageNum") int pageIndex, @PathVariable(name="pageSize") int pageSize) {
        ResultJson<?> res = roleSerivce.queryRole(role, pageIndex, pageSize);
        return res;
    }

    @ApiOperation(code="queryAllRole",name="查询所有角色",description = "查询所有角色",type="common")
    @AuditLog(object="Role",operation = "查询所有角色",type = OperationEnum.query)
    @RequestMapping(path = "/query/all",method = RequestMethod.GET)
    public ResultJson<?> getAllRole() {
        ResultJson<?> res = roleSerivce.queryAllRole();
        return res;
    }
    @ApiOperation(code="addRole",name="增加角色",description = "增加后台角色")
    @AuditLog(object="Role",operation = "增加角色",type = OperationEnum.add)
    @RequestMapping(path = "/add",method = RequestMethod.POST)
    public ResultJson<?> addRole(@RequestBody(required=false) Role role) {
        ResultJson<?> res = roleSerivce.add(role);
        return res;
    }

    @ApiOperation(code="deleteRole",name="删除角色",description = "后台删除角色")
    @AuditLog(object="Role",operation = "删除角色",type = OperationEnum.delete)
    @RequestMapping(path = "/delete",method = RequestMethod.POST)
    public ResultJson<?> deleteRole(@RequestBody(required=false) Role role) {
        ResultJson<?> res = roleSerivce.delete(role);
        return res;
    }

    @ApiOperation(code="getRoleMenus",name="获取角色菜单",description = "获取角色菜单",type="common")
    @AuditLog(object="Role",operation = "获取角色菜单",type = OperationEnum.query)
    @RequestMapping(path = "/menus/{roleCode}",method = RequestMethod.GET)
    public ResultJson<?> getRoleMenus(@PathVariable(name ="roleCode")String roleCode) {
        ResultJson<?> res = roleSerivce.getRoleMenus(roleCode);
        return res;
    }
}
